package com.meixiang.util;

import android.view.View;

import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.ObjectAnimator;

/**
 * 动画工具类
 *
 * @author LZRUI
 */
public class AnimUtil {

    /**
     * View淡入的动画
     * @param view
     */
    public static void viewAlphaIn(final View view) {
        ObjectAnimator anim = ObjectAnimator
                .ofFloat(view, "alpha", 0f, 1f)
                .setDuration(500);
        anim.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {

            }

            @Override
            public void onAnimationEnd(Animator animator) {
                view.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationCancel(Animator animator) {

            }

            @Override
            public void onAnimationRepeat(Animator animator) {

            }
        });
        anim.start();
    }

    /**
     * View淡出的动画
     * @param view
     */
    public static void viewAlphaOut(final View view) {
        ObjectAnimator anim = ObjectAnimator
                .ofFloat(view, "alpha", 1f, 0f)
                .setDuration(500);
        anim.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {

            }

            @Override
            public void onAnimationEnd(Animator animator) {
                view.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationCancel(Animator animator) {

            }

            @Override
            public void onAnimationRepeat(Animator animator) {

            }
        });
        anim.start();
    }
}
